package lin.an.auth.controller;

import cn.dev33.satoken.stp.StpUtil;
import lin.an.auth.param.LoginParam;
import lin.an.auth.service.LoginService;
import lin.an.pojo.CommonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhoulinq
 * @date 2025/4/1
 */
@Slf4j
@RestController
@RequestMapping("/do")
public class LoginController {
    @Autowired
    private LoginService loginService;


    @PostMapping("/login")
    public CommonResult<String> login(@RequestBody LoginParam loginParam) {

        return CommonResult.data(loginService.doLogin(loginParam));
    }

    @PostMapping("/logout")
    public CommonResult<String> logout() {
        StpUtil.logout();
        return CommonResult.ok("退出成功");
    }

    @GetMapping("/checkLogin")
    public CommonResult<String> checkLogin() {
        if (StpUtil.isLogin()) {
            log.info("登录情况：{}",StpUtil.isLogin());
            return CommonResult.ok("已登录");
        } else {
            return CommonResult.error("未登录");
        }
    }
}
